$OpenBSD: patch-plugins_flac_flac_c,v 1.1 2016/09/13 08:48:12 dcoppa Exp $

commit aa34db82ba64cc5f8d29b5109ddefd2811ca23e5
Author: Alexey Yakovenko <wakeroid@gmail.com>
Date:   Mon Aug 8 18:59:29 2016 +0200

flac: change embedded cue load order, to reduce a chance of loading
bad-formed native flac cuesheets

--- plugins/flac/flac.c.orig	Sun Jun 19 13:26:18 2016
+++ plugins/flac/flac.c	Wed Sep  7 16:40:48 2016
@@ -932,16 +932,6 @@ cflac_insert (ddb_playlist_t *plt, DB_playItem_t *afte
 
     // try embedded cue
     deadbeef->pl_lock ();
-    if (info.flac_cue_sheet) {
-        DB_playItem_t *cue = cflac_insert_with_embedded_cue (plt, after, it, &info.flac_cue_sheet->data.cue_sheet, info.totalsamples, info.info.fmt.samplerate);
-        if (cue) {
-            cflac_free_temp (_info);
-            deadbeef->pl_item_unref (it);
-            deadbeef->pl_item_unref (cue);
-            deadbeef->pl_unlock ();
-            return cue;
-        }
-    }
     const char *cuesheet = deadbeef->pl_find_meta (it, "cuesheet");
     if (cuesheet) {
         DB_playItem_t *last = deadbeef->plt_insert_cue_from_buffer (plt, after, it, (const uint8_t *)cuesheet, strlen (cuesheet), info.totalsamples, info.info.fmt.samplerate);
@@ -951,6 +941,16 @@ cflac_insert (ddb_playlist_t *plt, DB_playItem_t *afte
             deadbeef->pl_item_unref (last);
             deadbeef->pl_unlock ();
             return last;
+        }
+    }
+    if (info.flac_cue_sheet) {
+        DB_playItem_t *cue = cflac_insert_with_embedded_cue (plt, after, it, &info.flac_cue_sheet->data.cue_sheet, info.totalsamples, info.info.fmt.samplerate);
+        if (cue) {
+            cflac_free_temp (_info);
+            deadbeef->pl_item_unref (it);
+            deadbeef->pl_item_unref (cue);
+            deadbeef->pl_unlock ();
+            return cue;
         }
     }
     deadbeef->pl_unlock ();
